﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CCWin;

namespace weiqijiance.设备自检及检定
{
    public partial class qitisetting : CCSkinMain
    {
        public qitisetting()
        {
            InitializeComponent();
        }
        public mainform m_mainform;
        private void qitisetting_Load(object sender, EventArgs e)
        {
            init();
        }
        public void init()
        {
            skinDataGridView_qiti.Rows.Clear();
            string sql = string.Format("select * from qititable");
            DataTable dt = m_mainform.objdbbass.GetTable(sql);
            if (dt.Rows.Count > 0)
            {
                skinDataGridView_qiti.Rows.Add(dt.Rows.Count);
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    skinDataGridView_qiti.Rows[i].Cells[0].Value = dt.Rows[i]["ranyou"].ToString().Trim();    //填充第一列的数据 
                    skinDataGridView_qiti.Rows[i].Cells[1].Value = dt.Rows[i]["qitileixing"].ToString().Trim();    //填充第二列的数据 
                    skinDataGridView_qiti.Rows[i].Cells[2].Value = dt.Rows[i]["C3H8"].ToString().Trim();    //填充第二列的数
                    skinDataGridView_qiti.Rows[i].Cells[3].Value = dt.Rows[i]["CO"].ToString().Trim(); ;    //填充第二列的数据 据 
                    skinDataGridView_qiti.Rows[i].Cells[4].Value = dt.Rows[i]["NO"].ToString().Trim(); ;    //填充第二列的数据 
                    skinDataGridView_qiti.Rows[i].Cells[5].Value = dt.Rows[i]["CO2"].ToString().Trim(); ;    //填充第二列的数据 
                    skinDataGridView_qiti.Rows[i].Cells[6].Value = dt.Rows[i]["O2"].ToString().Trim(); ;    //填充第二列的数据 
                }
            }

            sql = string.Format("select * from btgtable");
            dt = m_mainform.objdbbass.GetTable(sql);
            if (dt.Rows.Count > 0)
            {
                text_N30.Text = dt.Rows[0]["N30"].ToString().Trim();
                text_N50.Text = dt.Rows[0]["N50"].ToString().Trim();
                text_N70.Text = dt.Rows[0]["N70"].ToString().Trim();    
            }
        }

        private void skinButton13_Click(object sender, EventArgs e)
        {

            string sql = string.Format("delete from qititable");
            m_mainform.objdbbass.InsertDB(sql);
            for (int i = 0; i < skinDataGridView_qiti.Rows.Count; i++)
            {
                if (skinDataGridView_qiti.Rows[i].Cells[0].Value==null)
                {
                    continue;
                }
                sql = string.Format("insert into qititable (ranyou,qitileixing,C3H8,CO,NO,CO2,O2) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}')",
                   Convert.ToString( this.skinDataGridView_qiti.Rows[i].Cells[0].Value),
                   Convert.ToString(this.skinDataGridView_qiti.Rows[i].Cells[1].Value),
                   Convert.ToString(this.skinDataGridView_qiti.Rows[i].Cells[2].Value),
                   Convert.ToString(this.skinDataGridView_qiti.Rows[i].Cells[3].Value),
                   Convert.ToString(this.skinDataGridView_qiti.Rows[i].Cells[4].Value),
                   Convert.ToString(this.skinDataGridView_qiti.Rows[i].Cells[5].Value),
                   Convert.ToString(this.skinDataGridView_qiti.Rows[i].Cells[6].Value));
                m_mainform.objdbbass.InsertDB(sql);
            }

        }

        private void skinButton1_Click(object sender, EventArgs e)
        {
            string sql = string.Format("select * from btgtable");
            DataTable dt = m_mainform.objdbbass.GetTable(sql);
            if (dt.Rows.Count > 0)
            {
                sql = string.Format("update btgtable set N30='{0}',N50='{1}',N70='{2}'",
                    text_N30.Text,
                    text_N50.Text,
                    text_N70.Text);
            }
            else
            {
                sql = string.Format("insert into btgtable (N30,N50,N70) values ('{0}','{1}','{2}')",
                    text_N30.Text,
                    text_N50.Text,
                    text_N70.Text);
            }
            m_mainform.objdbbass.InsertDB(sql);
        }
    }
}
